package amdocs.jet.pm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.amdocs.jet.pm.R;

import amdocs.jet.pm.safenote.common.SafeNote;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Utils 
{
	public static String formatDate(String iDate, String fromFormatPattern, String toFormatPattern)
	{
		SimpleDateFormat sdfDestination = new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT_PATTERN);
		SimpleDateFormat sdfSource = new SimpleDateFormat(Constants.ISRAEL_BANK_LAST_UPDATE_FORMAT_PATTERN);
		if (iDate == null || iDate.length() == 0)
		{
			return Constants.EMPTY_STRING;
		}
		try
	    {    
	    	if (fromFormatPattern != null)
	    	{
	    		// set default date formatter
	    		//create SimpleDateFormat object with desired date format
	    		sdfSource = new SimpleDateFormat(fromFormatPattern);
	    	}
	    	if (toFormatPattern != null)
	    	{
	    		// set default date formatter
	    		//create SimpleDateFormat object with desired date format
				sdfDestination = new SimpleDateFormat(toFormatPattern);
	    	}
			//parse the string into Date object
			Date date = sdfSource.parse(iDate);

			//parse the date into another format
			return sdfDestination.format(date);
	    }
	    catch(ParseException pe)
	    { 
	      System.out.println("Parse Exception : " + pe.getLocalizedMessage());
	      pe.printStackTrace();
	    }
		return null;
	}
	
	public static SafeNote convertSelectedNoteView2SafeNote(View selectedSafeNoteView)
	{
		SafeNote safeNote = new SafeNote();

		// set safe note id
		TextView safeNoteIDTextView = (TextView)selectedSafeNoteView.findViewById(R.id.safeNoteIDRow);
		if (safeNoteIDTextView != null)
		{
			safeNote.setSafeNoteID(safeNoteIDTextView.getText().toString());
		}
		
		// set safe note name
		TextView safeNoteNameTextView = (TextView)selectedSafeNoteView.findViewById(R.id.safeNoteNameRow);
		if (safeNoteNameTextView != null)
		{
			safeNote.setSafeNoteName(safeNoteNameTextView.getText().toString());
		}
		
		// set safe note icon
		TextView safeNoteIconTextView = (TextView)selectedSafeNoteView.findViewById(R.id.safeNoteIconNameRow);
		if (safeNoteIconTextView != null)
		{
			safeNote.setSafeNoteIcon(safeNoteIconTextView.getText().toString());
		}
		
		// set safe note category
		TextView safeNoteCategoryTextView = (TextView)selectedSafeNoteView.findViewById(R.id.safeNoteCategoryNameRow);
		if (safeNoteCategoryTextView != null)
		{
			safeNote.setSafeNoteCategoryName(safeNoteCategoryTextView.getText().toString());
		}
		
		// set safe note body
		TextView safeNoteBodyTextView = (TextView)selectedSafeNoteView.findViewById(R.id.safeNoteBodyRow);
		if (safeNoteBodyTextView != null)
		{
			safeNote.setSafeNoteBody(safeNoteBodyTextView.getText().toString());
		}
		return safeNote;
	}
}
